<?php

// 每天一次定时任务

namespace app\api\controller;

use app\api\controller\Base;
use app\api\controller\DayRecharge;
use app\api\controller\DayPaid;
use app\api\controller\DayUser;
use app\api\controller\FailNotify;
use app\api\controller\PaidQuery;
use app\api\controller\RefundQuery;

class EveryDay extends Base
{

    public function day()
    {
        try {
            // 只允许命令行访问
            if (PHP_SAPI != 'cli') {
                return ['code' => 999, 'msg' => '404'];
            }

            // 每天统计一次充值
            $day_recharge_obj = new DayRecharge();
            $day_recharge_obj->dayRecharge();

            // 每天统计一次代付
            $day_paid_obj = new DayPaid();
            $day_paid_obj->dayPaid();

            // 每天统计一次vip用户
            $day_user_obj = new DayUser();
            $day_user_obj->user();
        } catch (\Exception $e) {
            payment_error_log(999999, $e->getMessage());
            return ['code' => 999, 'msg' => '404'];
        }
    }

    /**
     * 每分钟执行一次
     */
    public function minute()
    {
        try {
            // 只允许命令行访问
            if (PHP_SAPI != 'cli') {
                return ['code' => 999, 'msg' => '404'];
            }

            // 多次通知控制器
            $fail_notify = new FailNotify();
            $fail_notify->query();

            // 代付查询通知
            $paid_query = new PaidQuery();
            $paid_query->query();

            // 退款查询通知
            $refund_query = new RefundQuery();
            $refund_query->query();
        } catch (\Exception $e) {
            payment_error_log(999999, $e->getMessage());
            return ['code' => 999, 'msg' => '404'];
        }
    }
}
